#include "user.pb.h"
#include "myrpcapplication.h"
#include "myrpcprovider.h"
#include <iostream>
#include <string>

class UserService : public user::UserServiceRPC
{
public:
    bool Login(const std::string& name, const std::string& pwd) {
        std::cout << "doing local service: Login\n";
        std::cout << "name: " << name << " pwd: " << pwd << "\n"; 
        return true;
    }

    void Login(google::protobuf::RpcController* controller,
               const user::LoginRequest* request,
               user::LoginResponse* response,
               google::protobuf::Closure* done)
    {
        // 获取name和pwd
        std::string name = request->name();
        std::string pwd = request->pwd();

        bool login_res = Login(name,pwd);

        user::ResultCode* code = response->mutable_result();
        code->set_errcode(0);
        code->set_errmsg("");
        response->set_success(login_res);

        done->Run();
    }
};

int main(int argc, char** argv) {
    // 初始化框架
    MyRPCApplication::init(argc,argv);

    MyRPCProvider rpcProvider;
    rpcProvider.NotifyService(new UserService());

    //rpc服务启动
    rpcProvider.Run();

    return 0;
}